package com.yyryyty.chapter6;

import com.yyryyty.chapter4.Dish;

import static com.yyryyty.chapter4.Dish.menu;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.summarizingInt;

/**
 * @Description :
 * @Author : YTY
 * @Date : 2021-01-18 08:40
 */
public class Grouping {

    public static void main(String[] args) {

//        System.out.println(menu.stream()
//                .collect(groupingBy(Dish::getType)));

//        System.out.println(menu.stream()
//                .collect(
//                        groupingBy(Dish::getType, counting())));

//        System.out.println(menu.stream()
//                .collect(groupingBy(Dish::getType,
//                        collectingAndThen(
//                                maxBy(Comparator.comparingInt(Dish::getCalories)),
//                                Optional::get
//                        ))));

//        System.out.println(menu.stream()
//                .collect(groupingBy(Dish::getType, summingInt(Dish::getCalories))));
//
//
//        System.out.println(menu.stream()
//                .collect(groupingBy(
//                        Dish::getType,
//                        collectingAndThen(
//                                minBy(Comparator.comparingInt(Dish::getCalories)),
//                                Optional::get
//                        )
//                )));


//        System.out.println(menu.stream()
//                .collect(partitioningBy(Dish::isVegetarian)).get(true));
//
//        System.out.println(menu.stream()
//                .filter(Dish::isVegetarian).collect(toList()));

//        menu.stream()
//                .collect(summingInt(Dish::getCalories))

//        System.out.println(menu.stream()
//                .mapToInt(Dish::getCalories)
//                .average()
//                .orElse(66.66));

        System.out.println(menu.stream()
                .collect(summarizingInt(Dish::getCalories)));

        System.out.println(menu.stream()
                .map(Dish::getName)
                .collect(joining(",")));

    }
}
